<template>
    <div :class="props.class">
        <el-popover placement="left" trigger="focus" :width="width" v-model:visible="visible">
            <div class="del_confirm">
                <span>{{title}}</span>
                <div class="flex-center ju-around">
                    <span @click="noClick">{{no}}</span>
                    <span @click="yesClick">{{yes}}</span>
                </div>
            </div>
            <template #reference>
                <u class="del_btn" @click="visible = true">{{text}}</u>
            </template>
        </el-popover>
    </div>
</template>

<script setup>
    import { ref } from 'vue'
    const emit = defineEmits(['yesClick','noClick'])

    const props = defineProps({
        title: { type: String, default: "确定要删除吗？" },
        yes:   { type: String, default: "确认" },
        no:    { type: String, default: "取消" },
        text:  { type: String, default: "删除" },
        width:  { type: Number, default: 150 },
        class: { type: String, default: "" }
    })

    let visible = ref(false)
    let yesClick = e => {
        visible.value = false
        emit('yesClick', e)
    }
    let noClick = e => {
        visible.value = false
        emit('noClick', e)
    }
</script>

<style scoped lang="scss">
    .del_confirm div { text-align: right; font-size: 12px; padding-top: 10px; 
        span:nth-child(1) { margin: 0 5px 0 0; cursor: pointer; }
        span:nth-child(2) { color: red; cursor: pointer; }
        .del_btn { cursor: pointer; }
    }
</style>